package com.zmh.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.zmh.entity.BookEntity;
import com.zmh.entity.QuartzEntity;


/** 
 * 定时任务数据库操作类
 * @author zhoumh
 * @version 创建时间：2018年7月15日 上午10:10:10 
 * @Description 
*/
@Mapper
public interface QuartzMapper {
	
	/**
	 * 分页查询全部类型的定时任务信息
	 * @return: List<QuartzEntity>
	 * @author: zhoumh
	 * @version: 创建时间：2018年7月22日 下午10:11:42 
	 * @Description:
	 */
	@Select("SELECT job.JOB_NAME as jobName,job.JOB_GROUP as jobGroup,job.DESCRIPTION as description,job.JOB_CLASS_NAME as jobClassName,cron.CRON_EXPRESSION as cronExpression,tri.TRIGGER_NAME as triggerName,tri.TRIGGER_STATE as triggerState,job.JOB_NAME as oldJobName,job.JOB_GROUP as oldJobGroup " 
			+"FROM qrtz_job_details AS job LEFT JOIN qrtz_triggers AS tri ON job.JOB_NAME = tri.JOB_NAME LEFT JOIN qrtz_cron_triggers AS cron ON cron.TRIGGER_NAME = tri.TRIGGER_NAME " 
			+"WHERE 1=1 LIMIT #{begin},#{size}")
	List<QuartzEntity> getAllByPage(@Param("begin")int begin, @Param("size")int size);
	
	/**
	 * 分页查询cron类型的定时任务信息
	 * @return: List<QuartzEntity>
	 * @author: zhoumh
	 * @version: 创建时间：2018年7月22日 下午10:11:42 
	 * @Description:
	 */
	@Select("SELECT job.JOB_NAME as jobName,job.JOB_GROUP as jobGroup,job.DESCRIPTION as description,job.JOB_CLASS_NAME as jobClassName,cron.CRON_EXPRESSION as cronExpression,tri.TRIGGER_NAME as triggerName,tri.TRIGGER_STATE as triggerState,job.JOB_NAME as oldJobName,job.JOB_GROUP as oldJobGroup " 
			+"FROM qrtz_job_details AS job LEFT JOIN qrtz_triggers AS tri ON job.JOB_NAME = tri.JOB_NAME LEFT JOIN qrtz_cron_triggers AS cron ON cron.TRIGGER_NAME = tri.TRIGGER_NAME " 
			+"WHERE tri.TRIGGER_TYPE = 'CRON' LIMIT #{begin},#{size}")
	List<QuartzEntity> getAllByCron(@Param("begin")int begin, @Param("size")int size);
	
	/**
	 * 查询cron类型的定时任务总数
	 * @return: int
	 * @author: zhoumh
	 * @version: 创建时间：2018年7月22日 下午10:11:42 
	 * @Description:
	 */
	@Select("SELECT COUNT(job.JOB_NAME) " 
			+"FROM qrtz_job_details AS job LEFT JOIN qrtz_triggers AS tri ON job.JOB_NAME = tri.JOB_NAME LEFT JOIN qrtz_cron_triggers AS cron ON cron.TRIGGER_NAME = tri.TRIGGER_NAME " 
			+"WHERE tri.TRIGGER_TYPE = 'CRON'")
	int getCountByCron();
	/**
	 * 查询全部类型的定时任务总数
	 * @return: int
	 * @author: zhoumh
	 * @version: 创建时间：2018年7月22日 下午10:11:42 
	 * @Description:
	 */
	@Select("SELECT COUNT(job.JOB_NAME) " 
			+"FROM qrtz_job_details AS job LEFT JOIN qrtz_triggers AS tri ON job.JOB_NAME = tri.JOB_NAME LEFT JOIN qrtz_cron_triggers AS cron ON cron.TRIGGER_NAME = tri.TRIGGER_NAME ")
	int getCount();
}
